package com.myspringboot.api;

import com.myspringboot.service.Data.TaskTestData;
import com.myspringboot.dao.domain.Student;
import com.myspringboot.dao.mapper.StudentMapper;
import com.myspringboot.service.work.WorkPoolTaskTest;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.myspringboot.workerpool.service.WorkPoolEntry;

/**
 * Created by guohuixin on 2017/12/3.
 */
@RestController
public class StudentController {
    private final Logger logger = LoggerFactory.getLogger(StudentController.class);

   @Autowired
   private StudentMapper studentMapper;

   @Autowired
   private WorkPoolTaskTest workPoolTaskTest;

   @Autowired
   private WorkPoolEntry workPoolEntry;

    @RequestMapping("/")
    @ResponseBody
    String home() {
        return "Hello World!";
    }
    @RequestMapping(value = "/select", method = {RequestMethod.GET, RequestMethod.POST})
    public @ResponseBody String selectStudent(@RequestBody String name){
        logger.info("student");
        //设置需要连接的是哪个数据库，此操作一般放在Dao层，直接进行主从数据库的负载均衡或者读写操作分离等

        Student students = studentMapper.selectAll().get(0);
        String age = "";
        age = students.getAge();
        TaskTestData data = new TaskTestData();
        data.setId(students.getId());
        data.setName(students.getName());
        workPoolEntry.setCallBack(workPoolTaskTest);
        //此处的data，是workPoolTaskTest这里面会用到的一些参数值
        workPoolEntry.launchTask("test", data);
        return age;
    }
}
